package ch.control;

import ch.entity.danger;
import ch.entity.result;
import ch.service.impl.dserviceimpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("d")
@RestController
public class dcontrol {
    @Autowired
    private dserviceimpl dserviceimpl;
    @GetMapping("getall")
    public result getall(){

        return result.success(dserviceimpl.getall());
    }
    @GetMapping("getone/{name}")
    public result getone(@PathVariable String name){
        danger getone = dserviceimpl.getone(name);
        System.out.println(getone);
        if (getone!=null){
            return result.success(getone);
        }
        else {
            return result.err("这个名称不对");
        }
    }
    @GetMapping("getonebyid/{id}")
    public result getonebyid(@PathVariable int id){
        return result.success(dserviceimpl.getonebyid(id));
    }
    @PostMapping("setone")
    public result setone(@RequestBody danger danger){
        System.out.println(danger.getDate());
        if (dserviceimpl.setone(danger)){
            return result.success("数据修改成功");
        }
        else {
            return result.err("数据修改失败 ");
        }
    }
    @PostMapping("insertone")
    public result insertone(@RequestBody danger danger){
        System.out.println("insert");
        if (dserviceimpl.insertone(danger)){
            return result.success("添加成功");
        }
        else {
            return result.err("添加失败");
        }

    }
}
